<template>
  <div class="bar">
    <div class="right">
      <t-button theme="primary" @click="onCreate()">
        <template #icon><t-icon name="add" /></template>
        {{ $t('common.create') }}
      </t-button>
    </div>
    <div class="title">{{ plugin.t('nav.outbound') }}</div>
  </div>
  <div class="bg-box">
    <t-button shape="square" variant="outline" @click="outboundStore.get" style="float: right">
      <template #icon>
        <t-icon name="refresh" />
      </template>
    </t-button>
    <t-form layout="inline" style="margin-bottom: 20px">
      <t-form-item label-width="0">
        <t-select v-model="outboundStore.where.key" style="width: 200px; margin-right: 10px">
          <t-option value="code" :label="plugin.t('outbound.code')" />
          <t-option value="name" :label="plugin.t('outbound.name')" />
        </t-select>
        <t-input v-model="outboundStore.where.value" style="width: 200px; margin-right: 10px">
          <template #prefix-icon>
            <t-icon name="search" />
          </template>
        </t-input>
        <Daterange type="time" v-model="outboundStore.where.time" style="width: 250px" />
      </t-form-item>
      <t-form-item label-width="0">
        <t-button theme="default" @click="outboundStore.reset(1)">{{ $t('common.search') }}</t-button>
      </t-form-item>
    </t-form>
    <Table 
      @info="onInfo" 
      @update="onCreate"
    />
    <Info ref="info" />
  </div>
</template>
<script setup>
  import { ref } from 'vue'
  import app from '@/app'
  import index from '../../index'
  import outboundStore from '../../store/outbound'
  import createStore from './create/store'
  import Table from './table.vue'
  import Info from './info/index.vue'
  import Daterange from '@/components/daterange.vue'

  const plugin = index.plugin
  const info = ref()

  const onCreate = () => {
    createStore.init()
    app.router.push('/plugin/goods/outbound/create')
  }

  const onInfo = data => {
    info.value.open(data)
  }
</script>